<template>
  <el-dialog
    ref="dislogRef"
    @close="dialogVisibleClose"
    :visible.sync="dialogVisible"
    lock-scroll
    width="50%"
  >
    <div slot="title" class="header_title">
      <span class="title_span">{{ logTitle }}</span>
    </div>
    <div class="content_div">
      <div class="info_table">
        <div class="div_table">
          <div class="table_content">
            <el-table :data="tableData" height="100%">
              <el-table-column min-width="50" type="index" label="编号"></el-table-column>
              <el-table-column
                min-width="100"
                property="createName"
                :label="logTitle == '办理过程' ? '办理人员' : '操作人员'"
              ></el-table-column>
              <el-table-column
                min-width="100"
                property="operationType"
                :label="logTitle == '办理过程' ? '办理过程' : '操作事项'"
              ></el-table-column>
              <el-table-column
                min-width="150"
                property="createTime"
                :label="logTitle == '办理过程' ? '办理日期' : '操作时间'"
              ></el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <div class="info_button">
        <el-button type="primary" @click.stop="dialogVisible = false">关闭</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { getAction } from '@/api/manage'
export default {
  name: 'dialogOperationLog',
  props: {
    logTitle: String,
  },
  data () {
    return {
      tableData: [],
      dialogVisible: false, // 新增弹框
      paramsData: {},
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.getBillData()
      } else {
        this.paramsData = {}
      }
    }
  },
  methods: {
    async getData(obj) {
      this.paramsData = obj
      // 避免提前请求
      if (!this.dialogVisible) {
        return
      }
      // 获取单位列表数据
      const res = await getAction('/xghProcessingProcessLog/xghProcessingProcessLog/queryList', obj)
      if (res.code === 200) {
        this.tableData = res.result
      }
    },
    async getBillData() {
      if (this.paramsData.orderId === -1) {
        return
      }
      let url = '/xghProcessingProcessLog/xghProcessingProcessLog/queryList'
      if (this.logTitle == '单据操作日志') {
        this.paramsData.billId = this.paramsData.orderId
        url = '/xghOperationLog/xghOperationLog/queryByBillId'
      }
      // 获取单位列表数据
      const res = await getAction(url, this.paramsData)
      if (res.code === 200) {
        this.tableData = res.result
        if (this.logTitle == '单据操作日志') {
          this.tableData.forEach((item, index) => {
            item.createTime = item.operationTime
          })
        }
      }
    },
    dialogVisibleClose () {
      this.tableData = []
      this.dialogVisible = false
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  width: 100%;
  margin-top: 20vh !important;
  .el-dialog__body {
    padding: 0;
  }
  .el-dialog__header {
    width: 100%;
    height: 50px;
    box-sizing: border-box;
    padding: 0 0.187512rem 0 0.281268rem;
    border-bottom: 1px solid #eeeeee;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .el-dialog__headerbtn {
      position: static;
      .el-icon-close {
        color: #999;
        font-size: 25px;
      }
    }
  }
  .header_title {
    width: 100%;
    display: flex;
    align-items: center;
    .title_span {
      white-space: nowrap;
      font-size: 16px;
      color: #666;
      font-weight: 600;
    }
  }
}
.content_div {
  width: 100%;
  height: 50vh;
  background: #fff;
  box-sizing: border-box;
  padding: 0.187512rem 0.281268rem;
  .info_table {
    width: 100%;
    height: calc(100% - 60px);
    display: flex;
    .div_table {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .table_content {
        height: 100%;
        ::v-deep .el-table {
          border: 1px solid #e3e3e3;
          box-sizing: border-box;
          th,
          td {
            padding: 0;
            color: #666;
            box-sizing: border-box;
            border-right: 1px solid #e3e3e3;
            .cell {
              height: 30px;
              display: flex;
              align-items: center;
              font-size: 12px;
            }
            &:first-child {
              .cell {
                justify-content: center;
              }
            }
          }
          th {
            .cell {
              background: #ededed;
              justify-content: center;
            }
          }
          .el-table__body tr:hover > td {
            background: #e3f6ff;
          }
          .el-table__footer-wrapper {
            td {
              background: #f4f4f4;
              border: none;
            }
          }
          //滚动条的宽度
          ::-webkit-scrollbar {
            width: 10px;
            height: 10px;
            background-color: #e5e5e5;
          }
          //滚动条的滑块
          ::-webkit-scrollbar-thumb {
            background-color: #c9c9c9;
          }
        }
      }
      .total_record {
        width: 100%;
        height: 0.562535rem;
        box-sizing: border-box;
        padding: 0 0.281268rem;
        border: 1px solid #e3e3e3;
        border-top: none;
        background: #f4f4f4;
        display: flex;
        p {
          margin: 0;
          line-height: 0.562535rem;
          padding-right: 0.281268rem;
          font-size: 0.225rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: #666666;
        }
      }
    }
  }
  .info_button {
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    ::v-deep .el-button {
      width: 90px;
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 5px;
    }
  }
}
</style>